﻿<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>开发流程</title>
    <script type="text/javascript" src="../../Content/highlighter/scripts/shCore.js"></script>
    <script type="text/javascript" src="../../Content/highlighter/scripts/shBrushJScript.js"></script>
    <script type="text/javascript" src="../../Content/highlighter/scripts/shBrushCSharp.js"></script>
    <script type="text/javascript" src="../../Content/highlighter/scripts/shBrushXml.js"></script>
    <link type="text/css" rel="stylesheet" href="../../Content/highlighter/styles/shCore.css" />
    <link type="text/css" rel="stylesheet" href="../../Content/highlighter/styles/shCoreEclipse.css" />
    <script type="text/javascript">SyntaxHighlighter.all();</script>
</head>
<body>
    <h3>开发流程</h3>
    <p>
        以下操作只能在VS2017下进行：<br />
    <p>
        1.创建基于.net framework 4.0的项目。<br />
        <img src="../../Content/images/SimpleWebApp/net40/新建项目.jpg" /><br />
        2.打开Nuget管理器<br />
        <img src="../../Content/images/SimpleWebApp/net40/管理Nuget.jpg" /><br />
        3.搜索NFinal包<br />
        <img src="../../Content/images/SimpleWebApp/搜索Nuget包.jpg" /><br />
        4.安装Nuget包<br />
        <img src="../../Content/images/SimpleWebApp/安装Nuget.jpg" /><br />
        5.在bin/下新建nfinal.json<br />
        <pre class="brush:javascript;">
        {
            //调试设置
            "debug": {
            "enable": true,
            "url": "http://localhost:59843",
            "directory": "/Debug"
            },
            //项目类型
            "projectType": "Web",
            "server": {
            "url": "http://www.domain.com",
            "indexDocument": "/Index.html"
            }
        }
        </pre>
        其中的debug.url必须和该项目属性中的一致。<br/>
        右键点击项目，选择属性->Web选项。<br />
        <img src="../../Content/images/SimpleWebApp/调试Url设置.jpg"/><br />
        6.在bin/新建 Plugs/SimpleWebApp目录。并于该目录下新建plug.json<br/>
        此处把宿主项目的程序集作为插件加载。<br/>
        <pre class="brush:javascript;">
        {
            "plug": {
            "enable": true,
            "name": "Main",
            "urlPrefix": null,
            "description": "网站",
            //当开发完成后，dll插件拷贝到当前目录下时，其路径为"/Plugs/CorePlug/NFinalCorePlug.dll".
            //这时插件就可以复制到Plugs目录下就能实现相应功能。
            "assemblyPath": "./SimpleWebApp.dll"
            },
            //用户自定义设置
            "appSettings": {
            "key": "value"
            },
            //连接字符串设置
            "connectionStrings": {
            "Common": {
                "connectionString": "Data Source=|ModuleDataDirectory|Common.db;Pooling=true;FailIfMissing=false",
                "providerName": "System.Data.SQLite"
            }
            },
            "verbs": [ "GET", "POST", "HEAD", "DEBUG" ],
            //Session设置
            "sessionState": {
            "cookieName": "session_id",
            "mode": "Redis",
            "stateConnectionString": "localhost",
            "timeout": 20,
            "prefix": ""
            },
            //Url设置
            "url": {
            "prefix": "",
            "extension": ".html",
            "defaultDocument": "index.html"
            },
            //Cookie设置
            "cookie": {
            "prefix": ""
            },
            //默认皮肤
            "defaultSkin": null,
            //用户自定义错误
            "customErrors": {
            "defaultRedirect": "Err.htm",
            "mode": "Off",
            "errors": [
                {
                "statusCode": 403,
                "redirect": "NoAccess.htm"
                },
                {
                "statusCode": 404,
                "redirect": "FileNotFound.htm"
                }
            ]
            }
        }
        </pre>
        7.把根目录下添加Startup类，代码如下：
        <pre class="brush:csharp;">
        using Owin;
        using Microsoft.Owin.Extensions;

        namespace NFinalWebSample
        {
            public class Startup
            {
                public void Configuration(IAppBuilder appBuilder)
                {
                    appBuilder.Use&lt;NFinal.Middleware.OwinMiddleware>();
                    appBuilder.UseStaticFiles();
                    appBuilder.UseStageMarker(PipelineStage.Authenticate);
                }
            }
        }
        </pre>
        8.修改Web.Config,添加runAllManagedModules属性，令Starup配置生效。
        <pre class="brush:xml">
        &lt;configuration>
            &lt;system.webServer>
                &lt;modules runAllManagedModulesForAllRequests="true">
                &lt;/modules>
            &lt;/system.webServer>
        &lt;/configuration>
        </pre>
            8.在根目录下新建BaseController
            <pre class="brush:csharp;">
            public class BaseController : NFinal.OwinAction
            {
                
            }
        </pre>
            9.在根目录下新建Controllers，并新建IndexController类
            <pre class="brush:csharp;">
            public class IndexController : BaseController
            {
                public void Index()
                {
                    this.Write("Hello World!");
                }
            }
        </pre>
            10.启动项目。在根目录下会生成/Debug/Index/Index.html,启动该调试文件。
            浏览器输出Hello World!
</p>

</body>
</html>
